package com.htz.agency.service.Impl;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.htz.agency.config.WebSocketServer;
import com.htz.agency.mapper.OrderMapper;
import com.htz.agency.pojo.Order;
import com.htz.agency.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author tang
 * @date 2025年06月28日 21:23
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private WebSocketServer webSocketServer;

    @Override
    public void add(Order order) {
        order.setCreateTime(new Date());
        Boolean flag = orderMapper.add(order);
        if (!flag){
            System.out.println("下单失败");
        }
        Map map=new HashMap();
        map.put("type",1);
        map.put("orderId",order.getId());
        map.put("content","订单号: {}"+order.getId()+"支付成功");

        log.info("map信息:{}", JSONUtil.toJsonStr( map));

        webSocketServer.sendToAllClient(JSONUtil.toJsonStr( map));

    }
}
